﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;
using CDStore3Tiers;

namespace CuaHangDiaNhac
{
    public partial class frmDanhSachDiaDatHang : DevComponents.DotNetBar.Office2007Form
    {
        StoreCDDataContext db = new StoreCDDataContext();
        DataGridViewTextBoxColumn colMaDH;
        DataGridViewTextBoxColumn colMaDia;
        DataGridViewTextBoxColumn colTenDia;
        DataGridViewTextBoxColumn colSoLuong;
        DataGridViewTextBoxColumn colDonGia;
        public void LoadDS(List<vwDSDDH> a)
        {
            BindingSource bd = new BindingSource();
            bd.DataSource = a;
            bindingNavigator1.BindingSource = bd;
            dgvDS.DataSource = bd;
        }
        public void LoadDGV(List<vwDSDDH> a)
        {
            dgvDS.DataSource = null;

            colMaDH = new DataGridViewTextBoxColumn();
            colMaDH.DataPropertyName = "MaDH";
            colMaDH.HeaderText = "Mã đặt hàng";
            colMaDH.Name = "cnameMaDH";
            colMaDH.Visible = false;
            dgvDS.Columns.Add(colMaDH);

            colMaDia = new DataGridViewTextBoxColumn();
            colMaDia.DataPropertyName = "MaDia";
            colMaDia.HeaderText = "Mã Đĩa";
            colMaDia.Name = "cnameMaDia";
            colMaDia.Visible = false;
            dgvDS.Columns.Add(colMaDia);

            colTenDia = new DataGridViewTextBoxColumn();
            colTenDia.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            colTenDia.DataPropertyName = "TenDia";
            colTenDia.HeaderText = "tên đĩa";
            colTenDia.Name = "cnameTenDia";
            dgvDS.Columns.Add(colTenDia);

            colSoLuong = new DataGridViewTextBoxColumn();
            colSoLuong.DataPropertyName = "SoLuong";
            colSoLuong.HeaderText = "Số lượng";
            colSoLuong.Name = "cnameSoLuong";
            dgvDS.Columns.Add(colSoLuong);


            colDonGia = new DataGridViewTextBoxColumn();
            colDonGia.DataPropertyName = "DonGia";
            colDonGia.HeaderText = "Đơn giá";
            colDonGia.Name = "cnameDonGia";
            dgvDS.Columns.Add(colDonGia);

            LoadDS(a);
        }
        XuLyDanhSachDiaDatHang dsdndh = new XuLyDanhSachDiaDatHang();
        public void GetDataDS(int maso)
        {
            try
            {
                var dh = db.ChiTietHoaDonBanHang_searchID(maso);
                if (dh != null)
                {
                    List<vwDSDDH> dsdh = dsdndh.XuLy(maso);
                                        //(from ds in db.vwDSDDHs
                                        //  where ds.MaDH == maso
                                        //  select ds).ToList<vwDSDDH>();
                    dgvDS.DataSource = dsdh;
                    LoadDGV(dsdh);
                }
                
            }
            catch (Exception)
            {
                dgvDS.DataSource = null;
            }
        }
        public frmDanhSachDiaDatHang(int maso)
        {
            InitializeComponent();
            GetDataDS(maso);
        }

        private void frmDanhSachDiaDatHang_Load(object sender, EventArgs e)
        {
            
        }
        
    }
}
